import 'package:ad_plugin/ad_error.dart';
import 'package:ad_plugin/ad_listener.dart';
import 'package:ad_plugin/insert_ad.dart';
import 'package:flutter/material.dart';

/// FileName insert_ad
/// @Author zhuqingfang
/// @Date 2022/10/8 4:18 下午
/// @Description insert ad
class InsertAdvertisement {
  InsertAdvertisement._internal();

  static final InsertAdvertisement _instance = InsertAdvertisement._internal();

  factory InsertAdvertisement() => _instance;
  InsertAd? _insertAd;

  void load() {
    InsertAd.load(
        placementId: 'ca-app-pub-3940256099942544/1033173712',
        adLoadCallback: AdLoadCallback(onAdLoaded: (InsertAd insertAd) {
          _insertAd = insertAd;
          debugPrint('insert ad load ');
        }, onAdFailLoad: (InsertAd insertAd,LoadAdError adError) {
          debugPrint('video ad load error $adError');
        }));
  }

  void show() {
    _insertAd?.contentCallback = ContentCallback(
        onAdShow: (InsertAd insertAd) {
          debugPrint('insert ad onShow');
        },
        onAdDismiss: (InsertAd insertAd) {
          debugPrint('insert ad onDismiss');
        },
        onAdClick: (InsertAd insertAd) {
          debugPrint('insert ad onClick');
        });
    _insertAd?.show();
  }

}
